<template>
  <div class="app-container">
    <label class="title"
           style="font-size: 20px;color: rgba(0,0,0,.85);font-weight: 600;line-height: 32px">考生报名管理</label>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="区县" prop="qy">
        <el-select v-model="queryParams.qy" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in qyList"
            :key="dict.n"
            :label="dict.n"
            :value="dict.v"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="学校" prop="zxmc">
        <el-select v-model="queryParams.zxmc" placeholder="请选择" clearable filterable size="small">
          <el-option
            v-for="dict in zxmcList"
            :key="dict.zxmc"
            :label="dict.zxmc"
            :value="dict.zxmc">
            <span style="float: left">{{ dict.zxmc }}</span>
            <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.zxdm }}</span>
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="bjdm">
        <el-select v-model="queryParams.bjdm" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in bjdmList"
            :key="dict.bjdm"
            :label="dict.bjdm"
            :value="dict.bjdm"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="准考号" prop="zkh">
        <el-input
          v-model="queryParams.zkh"
          placeholder="请输入准考号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="建档号" prop="jdh">
        <el-input
          v-model="queryParams.jdh"
          placeholder="请输入建档号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="考试状态" prop="kszt">
        <el-select v-model="queryParams.kszt" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in ksztList"
            :key="dict.n"
            :label="dict.n"
            :value="dict.v"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="qkzt">
        <el-select v-model="queryParams.qkzt" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in dict.type.qkzt"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:examSummaryResults:addAndEdit']"
        >新增报名
        </el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="candidateList">
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + (queryParams.pageNo - 1) * queryParams.pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="中学名称" align="center" prop="zxmc"/>
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="准考号" align="center" prop="zkh"/>
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.gender"/>
        </template>
      </el-table-column>
      <el-table-column label="考试状态" align="center">
        <template slot-scope="scope">
          <span>{{ returnStatus(scope.row) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="必测项" align="center" prop="bctyxm" width="220">
        <template slot-scope="scope">
          <span>{{ returnExamInfo(scope.row.bctyxm, scope.row.bctyxmStatus, scope.row.bctyxmValue) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="选测项1" align="center" prop="xctyxm1" width="200">
        <template slot-scope="scope">
          <span>{{ returnExamInfo(scope.row.xctyxm1, scope.row.xctyxm1Status, scope.row.xctyxm1Value) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="选测项2" align="center" prop="xctyxm2" width="200">
        <template slot-scope="scope">
          <span>{{ returnExamInfo(scope.row.xctyxm2, scope.row.xctyxm2Status, scope.row.xctyxm2Value) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="日常考核" align="center" prop="usualResults"/>
      <el-table-column label="状态" align="center" prop="qkzt"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            v-hasPermi="['business:candidates:detail']"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:candidates:update']"
          >编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改报名对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form :inline="true" ref="form" :model="form" :rules="rules" :disabled="disabled" label-width="80px">
        <el-collapse v-model="activeNames">
          <el-collapse-item title="考生信息" name="1" :disabled="true">
            <table id="table">
              <tr>
                <td>
                  <el-form-item label="姓名" prop="name" :disabled="true">
                    <el-input v-model="form.name" :disabled="true"/>
                  </el-form-item>
                </td>
                <td>
                  <el-form-item label="性别" prop="gender">
                    <el-select v-model="form.gender" :disabled="true" clearable size="small" class="selectWidth">
                      <el-option
                        v-for="dict in dict.type.sys_user_sex"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </td>
                <td rowspan="4" height="200px">
                  <el-input v-model="form.zp" style="display: none" :disabled="true"/>
                  <el-form-item label="照片" prop="zp">
                    <el-upload action="#" :http-request="requestUpload" :show-file-list="false"
                               :before-upload="uploadZp" :disabled="true">
                      <el-empty :image-size="70" description="点击上传照片" v-if="dialogImageUrl==null"></el-empty>
                      <el-image style="width: 160px; height: 200px" :src="dialogImageUrl"
                                v-if="dialogImageUrl!=null"></el-image>
                    </el-upload>
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <td>
                  <el-form-item label="准考号" prop="zkh">
                    <el-input v-model="form.zkh" :disabled="true"/>
                  </el-form-item>
                </td>
                <td>
                  <el-form-item label="建档号" prop="jdh">
                    <el-input v-model="form.jdh" :disabled="true"/>
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <td>
                  <el-form-item label="中学名称" prop="zxmc">
                    <el-select v-model="form.zxmc" filterable :disabled="true" clearable size="small"
                               @change="zxmcChange">
                      <el-option
                        v-for="dict in zxmcList"
                        :key="dict.zxmc"
                        :label="dict.zxmc"
                        :value="dict.zxdm">
                        <span style="float: left">{{ dict.zxmc }}</span>
                        <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.zxdm }}</span>
                      </el-option>
                    </el-select>
                  </el-form-item>
                </td>
                <td>
                  <el-form-item label="班级代码" prop="bjdm">
                    <el-input v-model="form.bjdm" :disabled="true"/>
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <td>
                  <el-form-item label="区县" prop="qy">
                    <el-select v-model="form.qy" filterable :disabled="true" clearable size="small"
                               class="selectWidth">
                      <el-option
                        v-for="dict in qyList"
                        :key="dict.n"
                        :label="dict.n"
                        :value="dict.v"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </td>
                <td>
                  <el-form-item label="身份证" prop="sfzh">
                    <el-input v-model="form.sfzh" :disabled="true"/>
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <td>
                  <el-form-item label="联系电话" prop="lxdh">
                    <el-input v-model="form.lxdh" :disabled="true"/>
                  </el-form-item>
                </td>
                <td>
                  <el-form-item label="平时分" prop="usualResults">
                    <el-input-number v-model="form.usualResults" :disabled="true"/>
                  </el-form-item>
                </td>
              </tr>
              <tr>
                <td colspan="2">
                  <el-form-item label="学校关联考点" prop="xxglkd" label-width="200">
                    <span v-if="form.xxglkd==null" style="color: #C03639"> {{ form.zxmc }}，未维护考试编排信息 </span>
                    <span v-if="form.xxglkd!=null">{{ form.xxglkd }}</span>
                  </el-form-item>
                </td>
              </tr>
            </table>
          </el-collapse-item>

          <el-collapse-item title="项目信息" name="2">
            <el-form-item label="必测项" prop="bctyxm">
              <el-select v-model="form.bctyxm" filterable class="selectWidth" disabled="disabled">
                <el-option
                  v-for="dict in projectIdList"
                  :key="dict.name"
                  :label="dict.name"
                  :value="dict.name"
                />
              </el-select>
            </el-form-item>
            <el-form-item prop="bcjszt">
              <el-checkbox-group v-model="checkboxGroup1" :disabled="jsDisabled" size="small"
                                 @change="checkboxClick1">
                <el-checkbox label="减试"></el-checkbox>
                <el-checkbox label="缓考"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="选测项1" prop="xctyxm1">
              <el-select v-model="form.xctyxm1" filterable placeholder="请选择" class="selectWidth">
                <el-option
                  v-for="dict in projectIdList"
                  :key="dict.name"
                  :label="dict.name"
                  :value="dict.name"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="xcjszt1">
              <el-checkbox-group v-model="checkboxGroup2" :disabled="jsDisabled" size="small"
                                 @change="checkboxClick2">
                <el-checkbox label="减试"></el-checkbox>
                <el-checkbox label="缓考"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <br>
            <el-form-item label="选测项2" prop="xctyxm2">
              <el-select v-model="form.xctyxm2" filterable placeholder="请选择" class="selectWidth">
                <el-option
                  v-for="dict in projectIdList"
                  :key="dict.name"
                  :label="dict.name"
                  :value="dict.name"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="" prop="xcjszt2">
              <el-checkbox-group v-model="checkboxGroup3" :disabled="jsDisabled"
                                 @change="checkboxClick3">
                <el-checkbox label="减试"></el-checkbox>
                <el-checkbox label="缓考"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="免试" prop="mszt">
              <el-select v-model="form.mszt" class="selectWidth" @change="msztChange">
                <el-option
                  v-for="dict in msztList"
                  :key="dict.n"
                  :label="dict.n"
                  :value="dict.v"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="必测项 减试/缓考原因" prop="bctyxmReason" label-width="90" :style="bctyxmDisplay">
              <el-input v-model="form.bctyxmReason" type="textarea" style="width: 600px"/>
            </el-form-item>
            <el-form-item label="选测项1减试/缓考原因" prop="xctyxm1Reason" label-width="90" :style="xctyxm1Display">
              <el-input v-model="form.xctyxm1Reason" type="textarea" style="width: 600px"/>
            </el-form-item>
            <el-form-item label="选测项2减试/缓考原因" prop="xctyxm2Reason" label-width="90" :style="xctyxm2Display">
              <el-input v-model="form.xctyxm2Reason" type="textarea" style="width: 600px"/>
            </el-form-item>
            <el-form-item label="免试原因" prop="reason" label-width="90" :style="mianshiDisplay">
              <el-input v-model="form.reason" type="textarea" style="width: 600px"/>
            </el-form-item>
          </el-collapse-item>
          <el-collapse-item name="3">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" style="width: 600px"/>
            </el-form-item>
          </el-collapse-item>

          <el-collapse-item title="考试记录列表" name="4">
            <el-table v-loading="loading" :data="candidateResultList">
              <el-table-column label="序号" type="index" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.$index + (query.pageNo - 1) * query.pageSize + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column label="考点名称" align="center" prop="pointName"/>
              <el-table-column label="考试项目名称" align="center" prop="examName"/>
              <el-table-column label="考试成绩" align="center" prop="result">
                <template slot-scope="scope">
                  <span
                    v-if="scope.row.resultTypeStr == '人工' ||scope.row.resultTypeStr == '设备' || scope.row.resultTypeStr == '修改成绩'">
                    {{ scope.row.result + scope.row.resultUnit }}
                  </span>
                  <span v-else>-</span>
                </template>
              </el-table-column>
              <el-table-column label="考试分数" align="center" prop="fraction">
                <template slot-scope="scope">
                  <span v-if="scope.row.resultTypeStr != '缓考' && scope.row.resultTypeStr != '重考'">
                    {{ scope.row.fraction + '分' }}
                  </span>
                  <span v-else>-</span>
                </template>
              </el-table-column>

              <el-table-column label="考试类型" align="center" prop="resultTypeStr"/>
              <el-table-column label="设备名称" align="center" prop="devName"/>
              <el-table-column label="原因" align="center" prop="reason"/>
              <el-table-column label="开始考试时间" align="center" prop="gmtStarted" width="100px">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.gmtStarted, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="结束考试时间" align="center" prop="gmtEnded" width="100px">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.gmtEnded, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="记录创建时间" align="center" prop="gmtCreated" width="100px">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.gmtCreated, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="状态" align="center" prop="resultStatusStr"/>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="updateCandidateResultList(scope.row)"
                    v-hasPermi="['business:examResults:cancelResultStatus']"
                  >取消成绩
                  </el-button>
                </template>
              </el-table-column>
            </el-table>

            <pagination
              v-show="total1>0"
              :total="total1"
              :page.sync="query.pageNo"
              :limit.sync="query.pageSize"
              @pagination="getExamResults"
            />
          </el-collapse-item>
        </el-collapse>
      </el-form>
      <div slot="footer" class="dialog-footer" id="footerId">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="passwordTitle" v-if="passwordOpen" :visible.sync="passwordOpen" width="500px">
      <el-form ref="passwordForm" :model="passwordForm" label-width="100px">
        <el-form-item label="密码" prop="password" :rules="{ required: true, message: '请输入密码', trigger: 'blur' }">
          <el-input type="password" v-model="passwordForm.password"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPasswordForm">确 定</el-button>
        <el-button @click="passwordCancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 选择考生 -->
    <el-dialog :title="chooseCandidate.dialogTitle" :visible.sync="chooseCandidate.dialogSync" width="800px"
               append-to-body>
      <candidateInfo v-on:listenToChildEvent="listenClient"></candidateInfo>
    </el-dialog>

  </div>
</template>
<style>
.selectWidth {
  width: 207.44px;
}

#table > tr > td > div {
  margin: 0px;
}
</style>
<script>
import {listSchool} from '@/api/business/school/school'

import {
  candidates,
  candidatesDetail,
  examProjectsList,
  examResultsList,
  schoolClass,
  updateCandidate,
  cancelResultStatus
} from '@/api/business/candidate/candidate'

import {getSuZhouQuYu} from '@/api/area'

import {uploadPhoto} from '@/api/system/user'

import candidateInfo from '@/views/business/candidate/info'

export default {
  name: 'candidateList',
  components: {
    candidateInfo
  },
  dicts: ['sys_user_sex', 'yes_no_1_0', 'qkzt', 'extra_password'],
  data() {
    return {
      passwordTitle: '',
      passwordOpen: false,
      passwordForm: {
        password: ''
      },
      passwordLabel: '',
      passwordRow: null,
      checkboxGroup1: [],
      checkboxGroup2: [],
      checkboxGroup3: [],
      // 遮罩层
      loading: true,
      // 选中数组
      selections: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total1: 0,
      // 考生表格数据
      candidateList: [],
      candidateList2: [],
      // 考生考试成绩列表
      candidateResultList: [],
      // 弹出层标题
      title: '',
      detailTitle: '',
      updateTitle: '',
      // 是否显示弹出层
      open: false,
      detailOpen: false,
      updateOpen: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        qy: null,
        zxmc: null,
        bjdm: null,
        zkh: null
      },
      query: {
        pageNo: 1,
        pageSize: 10,
        ksId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        qy: [
          {required: true, message: '区县不能为空', trigger: 'blur'}
        ],
        zkh: [
          {required: true, message: '准考号不能为空', trigger: 'blur'}
        ],
        jdh: [
          {required: true, message: '建档号不能为空', trigger: 'blur'},
          {min: 6, message: '建档号最少6位', trigger: 'blur'}
        ],
        name: [
          {required: true, message: '姓名不能为空', trigger: 'blur'}
        ],
        gender: [
          {required: true, message: '姓别不能为空', trigger: 'blur'}
        ],
        bjdm: [
          {required: true, message: '班级代码不能为空', trigger: 'blur'}
        ],
        zxmc: [
          {required: true, message: '中学名称不能为空', trigger: 'blur'}
        ],
        usualResults: [
          {required: true, message: '平时成绩不能为空', trigger: 'blur'}
        ],
        xctyxm1: [
          {required: true, message: '选测项1不能为空', trigger: 'blur'}
        ],
        xctyxm2: [
          {required: true, message: '选测项2不能为空', trigger: 'blur'}
        ],
        mszt: [
          {required: true, message: '是否免试不能为空', trigger: 'blur'}
        ]
      },
      zxmcList: [],
      bjdmList: [],
      projectIdList: [],
      doUpload: '',
      qyList: [],
      //图片
      dialogImageUrl: null,
      imageFile: null,
      disabled: false,
      activeNames: ['1', '2', '3'],
      jsDisabled: false,
      chooseCandidate: {
        dialogTitle: '',
        dialogSync: false
      },
      ksztList: [{n: '正常', v: '0'}, {n: '减试', v: '2'}, {n: '免考', v: '3'},
        {n: '重考', v: '4'}, {n: '缓考', v: '5'}],
      mianshiDisplay: null,
      bctyxmDisplay: null,
      xctyxm1Display: null,
      xctyxm2Display: null,
      msztList: [{n: '不免试', v: '0'}, {n: '免试9分', v: '9'}, {n: '免试15分', v: '15'}]
    }
  },
  created() {
    this.getList()
    listSchool().then(response => {
      this.zxmcList = response.rows
    })
    schoolClass().then(response => {
      this.bjdmList = response.data
    })
    examProjectsList().then(response => {
      this.projectIdList = response.data
    })
    getSuZhouQuYu().then(response => {
      this.qyList = response.data
    })
  },
  methods: {
    /** 查询考生列表 */
    getList() {
      this.loading = true
      candidates(this.queryParams).then(response => {
        const records = response.data.records
        this.candidateList = records
        this.total = response.data.totalCount
        this.loading = false
      })
    },
    /** 查询考试记录列表 */
    getExamResults() {
      this.loading = true
      examResultsList(this.query).then(result => {
        this.candidateResultList = result.data.records;
        this.total1 = result.data.totalCount
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        zkh: null,
        jdh: null,
        name: null,
        gender: null,
        zxdm: null,
        zxmc: null,
        bjdm: null,
        zp: null,
        bctyxm: '1000米/800米',
        bcjszt: null,
        xctyxm1: null,
        xcjszt1: null,
        xctyxm2: null,
        xcjszt2: null,
        mszt: '0',
        remark: null
      }
      this.dialogImageUrl = null
      this.query.pageNo = 1
      this.query.pageSize = 10
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.reset()
      const id = row.id
      candidatesDetail(id).then(response => {
        this.form = response.data
        const data = response.data;
        this.form.gender = data.gender + ''
        this.dialogImageUrl = data.zpStr
        this.form.qy = data.qy
        this.checkboxGroup1 = data.bcjszt === 0 ? [] : this.getText(data.bcjszt)
        this.checkboxGroup2 = data.xcjszt1 === 0 ? [] : this.getText(data.xcjszt1)
        this.checkboxGroup3 = data.xcjszt2 === 0 ? [] : this.getText(data.xcjszt2)
        this.form.mszt = data.mszt == null ? '' : (data.mszt + '')
        this.bctyxmDisplay = 'display: none'
        this.xctyxm1Display = 'display: none'
        this.xctyxm2Display = 'display: none'
        this.msztChange(this.form.mszt)
        this.disabled = true
        document.getElementById('footerId').style.display = 'none'
        // let query = { ksId: response.data.id }
        this.query.ksId = response.data.id
        examResultsList(this.query).then(result => {
          this.candidateResultList = result.data.records;
          this.total1 = result.data.totalCount
          this.open = true
          this.title = '考生详情'
        })
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id
      candidatesDetail(id).then(response => {
        this.form = response.data
        this.setFormInfo(response.data)
        this.disabled = false
        document.getElementById('footerId').style.display = 'block'
        this.query.ksId = response.data.id
        examResultsList(this.query).then(result => {
          this.candidateResultList = result.data.records;
          this.total1 = result.data.totalCount
          this.open = true
          this.title = '修改考生'
        })
      })
    },
    setFormInfo(data) {
      this.form.gender = data.gender + ''
      this.dialogImageUrl = data.zpStr
      this.form.qy = data.qy
      this.checkboxGroup1 = data.bcjszt === 0 ? [] : this.getText(data.bcjszt)
      this.checkboxGroup2 = data.xcjszt1 === 0 ? [] : this.getText(data.xcjszt1)
      this.checkboxGroup3 = data.xcjszt2 === 0 ? [] : this.getText(data.xcjszt2)
      this.form.mszt = data.mszt == null ? '' : (data.mszt + '')
      this.checkboxClick1(this.checkboxGroup1)
      this.checkboxClick2(this.checkboxGroup2)
      this.checkboxClick3(this.checkboxGroup3)
      this.msztChange(this.form.mszt)
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          const data = this.form
          //考生报名管理页面，type为1 只维护考生的项目报名信息
          data.type = 1
          //考生信息
          data.bcjszt = this.getType(this.checkboxGroup1)
          data.xcjszt1 = this.getType(this.checkboxGroup2)
          data.xcjszt2 = this.getType(this.checkboxGroup3)
          if (data.mszt != '0') {
            data.bctyxmReason = this.form.reason
            data.xctyxm1Reason = this.form.reason
            data.xctyxm2Reason = this.form.reason
          }
          if (this.form.id != null) {
            updateCandidate(data, this.form.id).then(response => {
              if (response.status === 'success') {
                this.$modal.msgSuccess('修改成功')
                this.open = false
                this.getList()
              } else {
                this.$modal.msgSuccess(response.message)
              }
            })
          }
        }
      })
    },
    handleExport() {
      //todo 打印未完成
    },
    resultqymc(value) {
      this.qyList.forEach(info => {
        if (info.v == value) {
          return value = info.n
        }
      })
      return value
    },
    // 覆盖默认的上传行为
    requestUpload() {
    },
    // 上传图片
    uploadZp(file) {
      if (file.type.indexOf('image/') == -1) {
        this.$modal.msgError('文件格式错误，请上传图片类型,如：JPG，PNG后缀的文件。')
      } else {
        const reader = new FileReader()
        reader.readAsDataURL(file)
        reader.onload = () => {
          this.dialogImageUrl = reader.result
          this.imageFile = file
          let formData = new FormData()
          formData.append('photofile', this.imageFile)
          uploadPhoto(formData).then(response => {
            this.dialogImageUrl = process.env.VUE_APP_BASE_API + response.imgUrl
            this.form.zp = response.imgUrl
            this.$modal.msgSuccess('上传成功')
          })
        }
      }
    },
    // 免试
    msztChange(value) {
      //免试
      if (value == 0) {
        this.mianshiDisplay = 'display: none'
        this.jsDisabled = false
      } else {
        this.checkboxGroup1 = []
        this.checkboxGroup2 = []
        this.checkboxGroup3 = []
        this.checkboxClick1([])
        this.checkboxClick2([])
        this.checkboxClick3([])
        this.jsDisabled = true
        this.mianshiDisplay = 'display: block'
      }
    },
    zxmcChange(value) {
      this.zxmcList.forEach(item => {
        if (item.zxdm == value) {
          this.form.qy = item.qxdm
        }
      })
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.chooseCandidate.dialogSync = true
      this.chooseCandidate.dialogTitle = '选择考生'
    },
    /** 选择器监听事件 */
    listenClient(data) {
      this.chooseCandidate.dialogSync = false
      candidatesDetail(data.id).then(response => {
        this.form = response.data
        this.setFormInfo(response.data)
        this.disabled = false
        this.open = true
        this.title = '新增考生报名信息'
      })
    },
    getType(value) {
      if (value.length === 0) {
        return 0
      }
      if (value[0] === '缓考') {
        return 5
      }
      if (value[0] === '减试') {
        return 2
      }
    },
    checkboxClick1(value) {
      if (value.length === 2) {
        this.checkboxGroup1 = [value[1]]
      }
      if (value.length > 0) {
        this.bctyxmDisplay = 'display: block'
      } else {
        this.bctyxmDisplay = 'display: none'
      }
    },
    checkboxClick2(value) {
      if (value.length === 2) {
        this.checkboxGroup2 = [value[1]]
      }
      if (value.length > 0) {
        this.xctyxm1Display = 'display: block'
      } else {
        this.xctyxm1Display = 'display: none'
      }
    },
    checkboxClick3(value) {
      if (value.length === 2) {
        this.checkboxGroup3 = [value[1]]
      }
      if (value.length > 0) {
        this.xctyxm2Display = 'display: block'
      } else {
        this.xctyxm2Display = 'display: none'
      }
    },
    getText(value) {
      if (value === 2) {
        return ['减试']
      }
      if (value === 5) {
        return ['缓考']
      }
      return []
    },
    returnExamInfo(name, status, value) {
      if (status === '缓考' || status === '未考' || status === '重考') {
        return name + ' - ' + status
      }
      if (status === '设备' || status === '人工') {
        return name + ' - 已考 - ' + value + '分'
      }
      if (name == null) {
        return '-'
      }
      return name + ' - ' + status + ' - ' + value + '分'
    },
    //考试状态
    returnStatus(row) {
      if (row.bctyxmStatus === '未考' || row.xctyxm1Status === '未考' || row.xctyxm2Status === '未考' ||
        row.bctyxmStatus === '缓考' || row.xctyxm1Status === '缓考' || row.xctyxm2Status === '缓考' ||
        row.bctyxmStatus === '重考' || row.xctyxm1Status === '重考' || row.xctyxm2Status === '重考') {
        return '未考完'
      }
      return '已考三项'
    },
    // 修改考试记录信息
    async updateCandidateResultList(data) {
      this.passwordOpen = true
      this.passwordTitle = '取消成绩'
      this.passwordForm.password = ''
      this.passwordRow = data
    },
    /** 输入密码 */
    submitPasswordForm() {
      this.$refs['passwordForm'].validate(valid => {
        if (valid) {
          this.dict.type.extra_password.forEach(item => {
            if (item.label === 'pw_qxcj') {
              if (this.passwordForm.password === item.value) {
                this.confirmCancelResultStatus(this.passwordRow);
              } else {
                this.$modal.msgError('密码错误');
              }
            }
          })
        }
      })
    },
    // 取消按钮
    passwordCancel() {
      this.passwordOpen = false
      this.passwordForm.password = ''
      this.passwordLabel = ''
      this.passwordRow = null
    },
    async confirmCancelResultStatus(data) {
      await cancelResultStatus(data.id).then((res) => {
          this.query.ksId = data.ksId
          examResultsList(this.query).then(result => {
            this.candidateResultList = result.data.records;
            this.total1 = result.data.totalCount
          });
          if (res.status === 'success') {
            this.$modal.msgSuccess('取消成功');
          } else {
            this.$modal.msgSuccess(res.message);
          }
          this.passwordCancel();
        }
      ).catch((res) => {
      });
    }
  }
}
</script>
